import { Component, OnInit } from '@angular/core';
import { SFSchema, SFButton } from '@delon/form';
import { STPage, STColumn } from '@delon/abc';
import { ThrowStmt } from '@angular/compiler';

@Component({
  selector: 'app-kfcs-jspz',
  templateUrl: './jspz.component.html',
})
export class KfcsJspzComponent implements OnInit {

  schema2: SFSchema = {
    properties: {
        title:{
          title:'列名',
          type:'string',
        },
        index:{
          title:'代码',
          type:'string',
        },

    }
  }


  schema: SFSchema = {
    properties: {
      top: {
        title: "取前几行",
        type: 'object',
        properties: {
          ORDER: {
            title: "排序方式",
            type: 'string',
            enum: ['DESC', 'ASC'],
            ui: {
              widget: 'select',
              allowClear: true,
              acl:'1'
            }
          },
          RN: {
            title: '数值',
            type: 'integer',
          }
        }
      },
      where: {
        title: '差异化条件',
        type: 'string'
      },
      agg: {
        title: '聚合方式',
        type: 'object',
        properties: {
          TYPE: {
            title: "聚合方式",
            type: 'string',
            enum: ['sum', 'avg', 'count', 'max', 'min', 'percentile'],
            ui: {
              widget: 'select',
              allowClear: true,
            }
          },
          NUM: {
            title: "数值",
            type: "number"
          }
        }
      },
      over: {
        title: '分析函数',
        type: 'object',
        properties: {
          TYPE: {
            title: "分析函数类型",
            type: 'string',
            enum: ['sum'],
            ui: {
              widget: 'select',
              allowClear: true,
            }
          },
          PARTITION: {
            title: '分组字段',
            type: 'string'
          }
        }
      }
    }
  }
  zbdata: any[] = [];
  selectItem: any = [];
  pzdata: any = {};
  isVisible = false;
  pzxx = '';

  searchSchema: SFSchema = {
    properties: {
      zbmc: {
        type: 'string',
        title: '请输入指标名称关键字',
        format: 'zbmc',
        maxLength: 20,
      },
    },
  };
  sfButton: SFButton = {
    search: '查询',
  };

  formData = {};
  formData2 = {};

  zbcolumns: STColumn[] = [
    { title: '指标编号', index: 'DAA020' },
    { title: '指标代码', index: 'DAA021' },
    { title: '指标名称', index: 'DAA022' },
    {
      title: '',
      buttons: [
        {
          text: '选择',
          type: 'link',
          click: (e: any) => {

            if (!this.zbdata.includes(e)) {
              this.zbdata = [...this.zbdata, e];
            }
          },
        },
      ],
    },
  ];

  stloading = null;
  // 表格参数
  pagecount = 0;
  pageps = 1;
  para = {};
  pi = 1;

  params = {
    sname: 'FR_zbclist',
    form: {
      zbmc: undefined,
    },
  };
  bqlist: any[]
  public stpage: STPage = {
    show: false,
    position: 'top',
  };

  constructor() {

  }

  ngOnInit() {
        

   }

  formSubmit($event) {

    if (this.selectItem) {
      this.pzdata[this.selectItem.DAA020] = $event
    }

    this.pzxx = JSON.stringify(this.pzdata);
  }

  showModal(): void {
    this.isVisible = true;
  }

  handleOk(): void {
    this.isVisible = false;
  }

  handleCancel(): void {
    this.isVisible = false;
  }

  clearSelect() {
    this.zbdata = [];
    this.pzdata = {};
  }

  pz(item) {
    this.selectItem = item;
    if (this.pzdata[item.DAA020]) {
      this.formData = this.pzdata[item.DAA020];
    } else {
      this.formData = {};
    }
  }

}
